package cn.itcast.bos.service.system.Impl;

import cn.itcast.bos.Dao.system.PermissionRepository;
import cn.itcast.bos.Dao.system.RoleRespostiory;
import cn.itcast.bos.domain.system.Permission;
import cn.itcast.bos.domain.system.User;
import cn.itcast.bos.service.system.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionRepository permissionRepository;
    @Override
    public List<Permission> findByUser(User user) {
        if(user.getUsername().equals("smbe")){
            return permissionRepository.findAll();
        }else{
            Integer id = user.getId();
            return permissionRepository.finByUser(id);
        }


    }

    @Override
    public List<Permission> findAll() {
        return permissionRepository.findAll();
    }

    @Override
    public void save(Permission model) {
        permissionRepository.save(model);
    }
}
